package StudentManagement2;

// Student.java
public class Student {
    // 私有属性（只能在本类访问）
    private String studentId;
    private String name;
    private int age;

    // getter方法：获取属性值
    public String getStudentId() {
        return studentId;
    }

    // setter方法：设置属性值
    public void setStudentId(String studentId) {
        this.studentId = studentId; // this表示当前对象
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    // 带验证的setter方法
    public void setAge(int age) {
        if (age >= 18 && age <= 30) {
            this.age = age;
        } else {
            System.out.println("年龄不合法（必须18-30岁）");
        }
    }
}
